//
//  NavAndTbbarView.m
//  EJLX
//
//  Created by adc on 15/11/9.
//  Copyright © 2015年 江苏一键联信息科技有限公司. All rights reserved.
//

#import "NavAndTbbarView.h"

@implementation NavAndTbbarView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
/*
 @property(nonatomic,strong)UIButton *btnBack;
 @property(nonatomic,strong)UIButton *leftBtn;
 @property(nonatomic,strong)UIButton *rightBtn;
 @property(nonatomic,strong)UIImageView *imgViewBg;
 @property(nonatomic,strong)UILabel *lableTitle;
 */
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    return self;
}
-(UIView*)initViewWithFrame:(CGRect)frame title:(NSString *)title  leftBtn:(SEL)leftAction  leftImg:(NSString*)leftImg {
    NavAndTbbarView *view = [[NavAndTbbarView alloc] initWithFrame:frame];
   
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _leftBtn.frame = CGRectMake(20, 5, 30, 30);
    _leftBtn.layer.cornerRadius = 20;
  //  _leftBtn.tag = 101;
    [_leftBtn setImage:[UIImage imageNamed:leftImg] forState:UIControlStateNormal] ;
    [_leftBtn addTarget:self action:leftAction forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_leftBtn];
    
 
    _lableTitle = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-100, 5, 200, 30)];
    _lableTitle.text = title;
    _lableTitle.textColor = [UIColor whiteColor];
    _lableTitle.textAlignment = NSTextAlignmentCenter;
    [view addSubview:_lableTitle];

    return view;  
}
-(UIView*)initViewWithFrame:(CGRect)frame title:(NSString *)title  leftBtn:(SEL)leftAction leftImg:(NSString*)leftImg rightBtn:(SEL)rightAction rightBtn:(NSString *)rightTitle andRightBtnFont:(CGFloat)font{
    NavAndTbbarView *view = [[NavAndTbbarView alloc] initWithFrame:frame];
    
    view.backgroundColor = [UIColor colorWithRed:(float)((0x00c49f&0xFF0000)>>16)/255.0 green:(float)((0x00c49f&0xFF00)>>8)/255.0 blue:(float)((0x00c49f&0xFF))/255.0 alpha:1];
   
    
    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _leftBtn.frame = CGRectMake(20, 5, 30, 30);
    _leftBtn.layer.cornerRadius = 20;
      _leftBtn.tag = 101;
    [_leftBtn setImage:[UIImage imageNamed:leftImg] forState:UIControlStateNormal] ;
    [_leftBtn addTarget:self action:leftAction forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_leftBtn];
    
    _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn.frame = CGRectMake(WIDE-70, 5, 50, 30);
  
    _rightBtn.titleLabel.font = [UIFont systemFontOfSize:font];
   // _rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    _rightBtn.layer.cornerRadius = 20;
    _rightBtn.tag = 102;
    [_rightBtn setTitle:rightTitle forState:UIControlStateNormal] ;
    [_rightBtn addTarget:self action:rightAction forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_rightBtn];
    
    _lableTitle = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-50, 5, 100, 30)];
    _lableTitle.text = title;
    [view addSubview:_lableTitle];
    
    return view;
}

-(UIView*)initViewWithFrame:(CGRect)frame title:(NSString *)title  leftBtn:(SEL)leftAction rightBtn:(SEL)rightAction btnImg:(NSArray*)imgArr {
    NavAndTbbarView *view = [[NavAndTbbarView alloc] initWithFrame:frame];
    

    _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _leftBtn.frame = CGRectMake(20, 5, 30, 30);
    _leftBtn.layer.cornerRadius = 20;
    _leftBtn.tag = 101;
    [_leftBtn setImage:[UIImage imageNamed:imgArr[0]] forState:UIControlStateNormal] ;
    [_leftBtn addTarget:self action:leftAction forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:_leftBtn];
    
   
        _rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBtn.frame = CGRectMake(WIDE-50, 5, 30, 30);
        _rightBtn.layer.cornerRadius = 20;
        _rightBtn.tag = 102;
        [_rightBtn setImage:[UIImage imageNamed:imgArr[1]] forState:UIControlStateNormal] ;
        [_rightBtn addTarget:self action:rightAction forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:_rightBtn];

    
    _lableTitle = [[UILabel alloc] initWithFrame:CGRectMake(WIDE/2-50, 5, 100, 30)];
    _lableTitle.text = title;
    [view addSubview:_lableTitle];
  
    return view;
}

-(UIView *)initTabbarViewWithFrame:(CGRect)frame  title:(NSArray *)titleArr  leftBtn:(SEL)leftAction  {
    NavAndTbbarView *view = [[NavAndTbbarView alloc] initWithFrame:frame];

    for (int i = 0; i<titleArr.count; i ++) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftBtn.frame = CGRectMake(((CGFloat)WIDE/titleArr.count) *i, 15, ((CGFloat)WIDE/titleArr.count)-1 , 40);
       // _leftBtn.layer.cornerRadius = 20;
        _leftBtn.tag = i;
        [_leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_leftBtn setTitle:titleArr[i]  forState:UIControlStateNormal] ;
        [_leftBtn addTarget:self action:leftAction forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:_leftBtn];
        UIView *small = [[UIView alloc] initWithFrame:CGRectMake(((CGFloat)WIDE/titleArr.count) *i, 10, 1, 40)];
        small.backgroundColor = [UIColor lightGrayColor];
        [view addSubview:small];
    }
    
 
    return view;
}

-(UIView *)initTabbarViewWithFrame:(CGRect)frame  img:(NSArray *)imgArr tag:(int)tag Btn:(SEL)action titlelB:(NSArray *)titleArr {
    NavAndTbbarView *view = [[NavAndTbbarView alloc] initWithFrame:frame];
//    view.layer.borderWidth = 0.3;
//    view.layer.borderColor = [UIColor grayColor].CGColor;
   
    for (int i = 0; i<titleArr.count; i ++) {
        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _leftBtn.frame = CGRectMake(((CGFloat)WIDE/titleArr.count) *i+40, 5, ((CGFloat)WIDE/titleArr.count)-80 , 30);
        // _leftBtn.layer.cornerRadius = 20;
        _leftBtn.tag = tag + i;
        [_leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_leftBtn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal] ;
        _leftBtn.layer.cornerRadius = 10;
        _leftBtn.backgroundColor = RGB(240, 240, 240);
        [_leftBtn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:_leftBtn];
        
        
        
        UILabel *titleLB = [[UILabel alloc] initWithFrame:CGRectMake(((CGFloat)WIDE/titleArr.count) *i+10, 35, ((CGFloat)WIDE/titleArr.count)-20 , 20)];
        titleLB.text = titleArr[i];
        titleLB.textAlignment = NSTextAlignmentCenter;
        titleLB.textColor = [UIColor blackColor];
        [view addSubview:titleLB];
        
//        UIView *small = [[UIView alloc] initWithFrame:CGRectMake(((CGFloat)WIDE/titleArr.count) *i, 10, 1, 40)];
//        small.backgroundColor = [UIColor lightGrayColor];
//        [view addSubview:small];
    }
   
    
    return view;
}

@end
